const arr = [1, 2, 3, 4, 2, 1]

function unique(arr) {
    let newArr = []
    for (let i = 0; i < arr.length; i++) {
        console.log(newArr.indexOf(arr[i]));
        
        if (newArr.indexOf(arr[i]) === -1) {
            newArr.push(arr[i])
        }
    }

    return newArr
}
console.log(unique(arr));